import {Component, Inject, Optional} from '@angular/core';
import {MAT_DIALOG_DATA} from "@angular/material";
import {GnForm, GnMessageService} from "geminis-ng";
import {HttpClient} from "@angular/common/http";

@Component({
  selector: 'gn-workflow-manage-history-stop-process',
  templateUrl: './stop-process.component.html'
})
export class StopProcessComponent extends GnForm {

  reason: string = '';

  constructor(@Optional() @Inject(MAT_DIALOG_DATA) private param: any,
              private httpClient: HttpClient,
              private messageService: GnMessageService) {
    super();
  }

  stop(): void {
    this.httpClient.post("/WORKFLOW-SERVICE/instances/" + this.param.id + "/stop?reason=" + this.reason, null)
      .subscribe(() => {
          this.dialog.confirmForm();
        },
        (error) => {
          const submitError = {
            message: "处理错误",
            error: error
          };
          this.messageService.error(submitError);
        });
  }

}
